package com.rtx.edi.platform.log.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rtx.edi.model.log.po.PlApiRequestContentLog;
import com.rtx.edi.model.log.po.PlApiRequestLog;
import com.rtx.edi.platform.log.mapper.PlApiRequestLogMapper;
import com.rtx.edi.platform.log.service.PlApiRequestLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * api请求日志表  服务实现类
 * </p>
 *
 * @author wq
 * @since 2023-03-14
 */
@Service
public class PlApiRequestLogServiceImpl extends ServiceImpl<PlApiRequestLogMapper, PlApiRequestLog> implements PlApiRequestLogService {

    @Override
    public void selectPlDepartmentList(Page<PlApiRequestLog> pageParam, PlApiRequestLog plApiRequestLog) {
        LambdaQueryWrapper<PlApiRequestLog> query = new LambdaQueryWrapper<>();
        //排序方式：按日志流水号降序排序
        query.orderByDesc(PlApiRequestLog::getId);
        if(plApiRequestLog != null){
            // 查询条件：日志流水号、请求公司名称、请求应用名称、请求应用环境名称、接收公司名称、
            // 接收应用名称、接收应用环境名称、请求地址、请求接口编号、请求接口名称、响应码
            query.eq(StringUtils.hasText(plApiRequestLog.getLogNo()),PlApiRequestLog::getLogNo,plApiRequestLog.getLogNo())
                    .like(StringUtils.hasText(plApiRequestLog.getRequestCompanyName()),PlApiRequestLog::getRequestCompanyName,plApiRequestLog.getRequestCompanyName())
                    .like(StringUtils.hasText(plApiRequestLog.getRequestApplicationName()),PlApiRequestLog::getRequestApplicationName,plApiRequestLog.getRequestApplicationName())
                    .like(StringUtils.hasText(plApiRequestLog.getRequestEnvironmentName()),PlApiRequestLog::getRequestEnvironmentName,plApiRequestLog.getRequestEnvironmentName())
                    .like(StringUtils.hasText(plApiRequestLog.getResponseCompanyName()),PlApiRequestLog::getResponseCompanyName,plApiRequestLog.getResponseCompanyName())
                    .like(StringUtils.hasText(plApiRequestLog.getResponseApplicationName()),PlApiRequestLog::getResponseApplicationName,plApiRequestLog.getResponseApplicationName())
                    .like(StringUtils.hasText(plApiRequestLog.getResponseEnvironmentName()),PlApiRequestLog::getResponseEnvironmentName,plApiRequestLog.getResponseEnvironmentName())
                    .like(StringUtils.hasText(plApiRequestLog.getRequestUrl()),PlApiRequestLog::getRequestUrl,plApiRequestLog.getRequestUrl())
                    .eq(StringUtils.hasText(plApiRequestLog.getRequestInterfaceNo()),PlApiRequestLog::getRequestInterfaceNo,plApiRequestLog.getRequestInterfaceNo())
                    .like(StringUtils.hasText(plApiRequestLog.getRequestInterfaceName()),PlApiRequestLog::getRequestInterfaceName,plApiRequestLog.getRequestInterfaceName())
                    .like(StringUtils.hasText(plApiRequestLog.getLogkey()),PlApiRequestLog::getLogkey,plApiRequestLog.getLogkey())
                    .eq(plApiRequestLog.getResponseCode() != null,PlApiRequestLog::getResponseCode,plApiRequestLog.getResponseCode());
        }
        baseMapper.selectPage(pageParam,query);
    }
}
